package com.linkage.educloud.ah;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.linkage.educloud.ah.config.AccountConfig;
import com.linkage.educloud.ah.data.WsContentResovler;
import com.linkage.educloud.ah.http.EasyUtils;
import com.linkage.educloud.ah.vnet.ErrorMessage;
import com.linkage.educloud.ah.vnet.LinkagePushUtils;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;
import com.zzhou.common.library.MyActivityManager;

import java.util.ArrayList;

import static com.linkage.educloud.ah.Constants.HOST;

/**
 * <desc>
 * Created by The Moss on 2018/7/23.
 */

public class MyApplication extends Application {
    static MyApplication instance;
    WsContentResovler mResovler;

    private boolean hasLoginIm = false;
    public ArrayList<ErrorMessage> mIMessage = new ArrayList<>();

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        MyActivityManager.instance(this);
        mResovler = WsContentResovler.getResolver(this);
        AccountConfig.initialize(this);
        EasyUtils.initEasyHttp(this, HOST);

        //友盟分享初始化
        UMConfigure.setLogEnabled(false);
        UMConfigure.init(this, "55770c1f67e58e7f4b001549", "umeng", UMConfigure.DEVICE_TYPE_PHONE, "");
        PlatformConfig.setWeixin("wxb7f451b55b3cd9cd", "5bb696d9ccd75a38c8a0bfe0675559b3");
        PlatformConfig.setQQZone("1105051522", "c7394704798a158208a74ab60104f0ba");
    }

    public static MyApplication getInstance() {
        return instance;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    public WsContentResovler getResovler() {
        return mResovler;
    }

    public boolean isHasLoginIm() {
        return hasLoginIm;
    }

    public void setHasLoginIm(boolean hasLoginIm) {
        this.hasLoginIm = hasLoginIm;
    }

    public void logout(boolean clearAccount) {
        clearTargetMessage();
        LinkagePushUtils.closePush();
    }

    public void queTargetMessage(ErrorMessage msg) {
        synchronized (mIMessage) {
            if (mIMessage != null) {
                mIMessage.add(msg);
            }
        }
    }

    public void clearTargetMessage() {
        synchronized (mIMessage) {
            if (mIMessage == null) {
                mIMessage.clear();
            }
        }
    }
}
